import axios from 'axios'
import NproGress from 'nprogress'
import 'nprogress/nprogress.css'

axios.defaults.baseURL = 'https://bjwz.bwie.com'

axios.defaults.timeout = 30000


//  axios 拦截请求 再发起请求的时候 做的事情 
axios.interceptors.request.use((config) => {
    // axios 发起请求时  开启进度条
    NproGress.start()
    return config
})


// axios 响应 
axios.interceptors.response.use((data) => {
    // axios 响应  关闭进度条
    NproGress.done()
    return data
}, (error) => {
    switch (error.response.data.statusCode) {
        case 401:
            alert(error.response.data.msg)
            break
    }
}
)

export default axios

